﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：ApiLogHelper.cs
// 功能描述：TongTongMall.MallWeb.ApiRepository
// 
// Create User：jym 2017/02/28
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Castle.Core.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Dependecy;
using TongTongMall.Logging;

namespace TongTongMall.MallWeb.ApiRepository.Domain.Logger
{
    public class ApiLogHelper
    {
        public static ILogger Logger { get; private set; }

        static ApiLogHelper()
        {
            Logger = IocManager.Instance.IsRegistered(typeof(ILoggerFactory))
                ? IocManager.Instance.Resolve<ILoggerFactory>().Create("ApiRequestLog")
                : NullLogger.Instance;
        }

        public static void LogException(Exception ex)
        {
            LogException(Logger, ex);
        }

        public static void LogException(ILogger logger, Exception ex)
        {
            var severity = (ex is IHasLogSeverity)
                    ? (ex as IHasLogSeverity).Severity
                    : LogSeverity.Error;
            logger.Log(severity, ex.Message, ex);
        }
    }
}
